package states
{
	import org.flixel.*;
	
	import levels.*;
	import items.*;
	
	/**
	 * ...
	 * @author JAC
	 */
	public class SelectState extends PlayState
	{
		private static var _menuGrave:Entity;
		
		override public function create():void
		{
			super.create();
			
			includeLayer(_misc);
			includeLayer(_animations);
			includeLayer(Registry.levelGraves);
			
			_maze.load(MazeData.select);
			Player.spawnAt(1, 7);
			
			_misc.add(_menuGrave);
			
			Tracker.init();
			_ui.resetText();
			
			MusicPlayer.play(MusicPlayer.TOMB);
		}
		
		override public function destroy():void
		{
			_misc.clear();
			
			super.destroy();
		}
		
		override public function update():void
		{
			if (Registry.paused)
			{
				return;
			}
			
			super.update();
			
			_menuGrave.say("overlap");
			
			if (FlxG.overlap(_player, _menuGrave))
			{
				if (FlxG.keys.justPressed("SPACE"))
				{
					FlxG.switchState(new MenuState());
				}
			}
			
			if (_ui._itemOne == null)
			{
				_ui.insertItem(new SpeedBooster(0, 0));
			}
		}
		
		public static function init():void
		{
			initGraves();
		}
		
		private static function initGraves():void
		{
			_menuGrave = new Entity(1, 6);
			_menuGrave.loadGraphic(Assets.ImgGrave);
			_menuGrave.addText("overlap", "Main menu", 60, 3);
		}
	}
}